<include file="header" />
<div class="wraper">
	<div class="load">
		<img class="load-bee" src="/assets/base/laundry/images/load-bee.png">

	</div>
	<if condition="$themeCount gt 0">
		<div class="head clearfix">
			<a href="{BEESCRM::U('/Base/center/center',array('account_id'=>$accountId))}" onclick="abc()" class="iconfont icon-zuo pull-left"></a>
			<span class="head-name pull-left">{BEESCRM:$app_name}</span>
			<a href="{BEESCRM::U('/Base/center/center',array('account_id'=>$accountId))}" onclick="abc()" class="iconfont icon-shouye pull-left text-right"></a>
		</div>
	</if>
	<div class="lists tb-mode indexlist">
		<div class="tb-cell">
			<p class="padding-b">时长余额</p>
			<p class="resttime">{BEESCRM:$data.overplus_time}</p>
		</div>
		<div class="tb-cell charge">
			<p><a href="/index.php?g=base&m=laundry&a=recharge&laundryId={BEESCRM:$laundryId}" onclick="abc()">充值</a></p>
			<p><a href="{BEESCRM::U('/base/laundry/log',array('laundryId'=>$laundryId))}" onclick="abc()" class="history">历史记录<span class="iconfont icon-you"></span></a></p>
		</div>
	</div>
	<div class="clothes"><img src="/assets/base/laundry/images/clothes.png"/></div>
	<div class="btn-box half-btn" style="padding: 10% 25%;">
		<a href="#" class="btn laundry" onclick="abc()">去洗衣</a>
		<a href="javascript:void(0)" class="btn white-btn near">查看网点</a>
		<if condition="$is_refund eq 1">
			<div style="height:10px;"></div>
			<a href="#" id="refund" class="btn">申请余额退款</a>
		</if>
	</div>
	<div class="bottom-box">
		<p class="copyright">杭州青橄榄网络技术有限公司 技术支持</p>
		<div class="banner">
			<div class="swiper-container"> 
				<div class="swiper-wrapper">
					<if condition="count($adInfo) egt 1">
						<volist name="adInfo" id="vo">
							<div class="swiper-slide"><a href="#" onclick='stat(this,"{BEESCRM:$vo.url}")'>{BEESCRM:$vo.content}</a></div>
						</volist>
					<else/>
						<div><a href="javascript:void(0);"><img src="/assets/base/center/images/adds.jpg"></a></div>
					</if>
				</div>
				<div class="swiper-pagination"></div>
			</div>
		</div>
    </div>
</div>

<include file="commonJS" />
<include file="share_header" />
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
	var height = $(document).height();
	var bottombox_height = $('.bottom-box').outerHeight();
	$('.wraper').css("minHeight",height);
	$('.wraper').css("paddingBottom",bottombox_height);

    $(window).load(function(){
        $('.load').hide();
    });
    $('.tab-prize').on('click','.option',function(){
        if($(this).hasClass('other')){
            $(this).addClass('checked').siblings().removeClass('checked');
        }
        else{
            $(this).toggleClass('checked').siblings().removeClass('checked');
        }
    });
    //调起二维码扫一扫
    $(document).on('click','.laundry',function(){
        wx.scanQRCode({
            needResult: 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
            scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
            success: function (res) {
                var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
            }
        });
    });
    $(document).on('click','.near',function(){
        wx.getLocation({
            type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
            success: function (res) {
                var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                var speed = res.speed; // 速度，以米/每秒计
                var accuracy = res.accuracy; // 位置精度
                if(latitude && longitude){
                    abc();
                    location.href = "/base/laundry/near/latitude/"+latitude+"/longitude/"+longitude+"/laundryId/{BEESCRM:$laundryId}";
                }else{
                    alert('地理位置获取失败不能查看网点');
                }
            }
        });
    });

    $(function() {
		//退款
		$('#refund').on('click', function () {
			var msg = '申请退款后剩余时长将清0,进入待退款状态，是否继续？';
			$.confirm(msg, drop);
			function drop() {
				$.ajax({
					url: "{BEESCRM::U('Base/Laundry/applyRefund',array('laundryId'=>$laundryId))}",
					dataType: "json",
					success: function (res) {
						if(res.status == 'S') {
							$.alert('success',res.message);
						} else {
							$.alert('error',res.message);
						}
					}
				});
			}
		})
	});

	var swiper = new Swiper('.banner .swiper-container', {
        //		pagination: '.banner .swiper-pagination',
        paginationClickable: true,
        spaceBetween: 30,
        centeredSlides: true,
        autoplay: 2500,
        autoplayDisableOnInteraction: false,
        //广告统计
        onSlideChangeStart:function(swiper){
            myCount(swiper);
        }
    });

    //广告统计
    //定义数组
    var ads = {};
    //循环数组,构建以广告id为键，曝光次数为值的数组
    $(".swiper-slide").each(function(i,node){
        ads[i] = {};
        var img = $(node).find("img");
        var id = $(img).data('id');
        ads[i][0] = id;
        if(i == 0){
            ads[i][1] = 1;
        }else {
            ads[i][1] = 0;
        }
    });

    function myCount(swiper){
        ads[swiper.activeIndex][1] = ads[swiper.activeIndex][1]+1;
//        alert(swiper.activeIndex);
    }

	function stat(img,jumpUrl) {
        //还可以把this传到stat里。。。
		var imgObj = $(img).find("img");
		var id = imgObj.data('id');
		$.ajax({
			url: '/base/Laundry/adStat/laundryId/{BEESCRM:$laundryId}',
			method: 'post',
			dataType: 'json',
			data: {ad_id:id},
			success: function(result) {
				console.log(result.err_code);
				console.log(result.err_msg);
			},
			error: function(error) {
				console.log(error);
			}
		});
        if(jumpUrl != 'javascript:void(0)' && jumpUrl != '#' && jumpUrl != ''){
            abc();
        }
        //跳转到原来的地址
		window.location.href = jumpUrl;
	}

//    $(window).unload(function(){
//        abc();
//    });

    if(document.addEventListener){
        document.addEventListener('WeixinJSBridgeReady', send(), false);
    }else if(document.attachEvent){
        document.attachEvent('WeixinJSBridgeReady' , send());
        document.attachEvent('onWeixinJSBridgeReady' , send());
    }

    function send(){
        WeixinJSBridge.invoke('closeWindow',{},function(res){
            abc();
//        alert(res.err_msg);
        });

    }

    function abc (){
        $.ajax({
            url:'/base/Laundry/adStat/laundryId/{BEESCRM:$laundryId}',
            method:'post',
            dataType:'json',
            data:{data:ads},
            success:function(result){}
        });
    }

    //广告统计结束
</script>
</body>
</html>